/*
 * @(#)XfsimOutputDialog.java        2003/01/01
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//		DIALOGO PARA CREAR UNA NUEVA SALIDA		//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

package xfuzzy.xfsim.view;

import xfuzzy.lang.*;
import xfuzzy.util.*;
import xfuzzy.xfsim.model.*;
import xfuzzy.xfsim.view.listener.XfsimOutputActionListener;
import javax.swing.*;
import java.awt.*;

/**
 * Di�logo para crear una salida (plot o log) de un proceso de simulaci�n
 * 
 * @author Francisco Jos� Moreno Velo
 *
 */
public class XfsimOutputDialog extends JDialog {
	
	//----------------------------------------------------------------------------//
	//                            COSTANTES PRIVADAS                              //
	//----------------------------------------------------------------------------//

	/**
	 * C�digo asociado a la clase serializable
	 */
	private static final long serialVersionUID = 95505666603060L;
	
	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                               //
	//----------------------------------------------------------------------------//
	
	/**
	 * Ventana principal de la aplicaci�n
	 */
	private Xfsim xfsim;
	
	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//

	/**
	 * Constructor
	 */
	public XfsimOutputDialog(Xfsim xfsim) {
		super(xfsim,"Xfsim",true);
		this.xfsim = xfsim;
		build();
	}
	
	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//
			
	/**
	 * Crea un nuevo fichero de almacenamiento hist�rico
	 */
	public void insertLogfile() {
		setVisible(false);
		Variable[] input = xfsim.getSpecification().getSystemModule().getInputs();
		Variable[] output = xfsim.getSpecification().getSystemModule().getOutputs();
		XfsimLog logfile = new XfsimLog(input.length, output.length);
		
		XfsimLogDialog dialog = new XfsimLogDialog(xfsim,logfile);
		dialog.setVisible(true);
		if(dialog.getResult()) {
			xfsim.getConfiguration().addOutput(logfile);
			xfsim.refreshConfig();
		}
	}
	
	/**
	 * Crea una nueva representaci�n gr�fica
	 */
	public void insertPlot() {
		setVisible(false);
		XfsimPlot plot = new XfsimPlot("n","o0",0);
		XfsimPlotDialog dialog = new XfsimPlotDialog(xfsim,plot);
		dialog.setVisible(true);
		if(dialog.getResult()) {
			xfsim.getConfiguration().addOutput(plot);
			xfsim.refreshConfig();
		}
	}

	//----------------------------------------------------------------------------//
	//                             M�TODOS PRIVADOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Construye el contenido de la ventana
	 */
	private void build() {
		XfsimOutputActionListener listener = new XfsimOutputActionListener(this);
		String lb[] = { "Insert new log file", "Insert new plot" };
		String cm[] = { "Logfile", "Plot" };
		XCommandForm form = new XCommandForm(lb,cm,listener);
		form.setCommandWidth(200);
		
		Container content = getContentPane();
		content.setLayout(new BoxLayout(content,BoxLayout.Y_AXIS));
		content.add(new XLabel("Select output to insert"));
		content.add(form);
		
		Point loc = xfsim.getLocationOnScreen();
		loc.x += 40; loc.y += 200;
		this.setLocation(loc);
		pack();
	}
}
